﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Demo_Skin01
{
    public partial class WebForm1 : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            WriteTheme(ParaTheme);
        }


        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Request.Cookies["Theme"] != null)
                Page.Theme = Request.Cookies["Theme"].Value;
        }

        public string ParaTheme
        {
            get
            {
                if (String.IsNullOrEmpty(Request.QueryString["theme"]))
                    return "Admin";
                return Request.QueryString["theme"].ToString();
            }
        }

        private void WriteTheme(string theme)
        {
            var selTheme = new HttpCookie("Theme") { Value = theme, Expires = DateTime.Now.AddMonths(1) };
           
            if (Response.Cookies["Theme"] == null)
                Response.Cookies.Add(selTheme);
            else
            {
                Response.Cookies.Remove("Theme");
                Response.Cookies.Add(selTheme);
            }
        }
    }
}